package com.xlh.support.training.dao.helper;

import com.xlh.support.training.dao.TrainingReportMapper;
import com.xlh.support.training.domain.TrainingReport;
import com.xlh.support.training.domain.example.TrainingReportExample;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cheer
 */
@Repository
public class TrainingReportMapperHelper {

    @Autowired
    private TrainingReportMapper trainingReportMapper;

    public List<TrainingReport> listByUserIds(List<Long> userIds) {
        if (CollectionUtils.isEmpty(userIds)) {
            return new ArrayList<>();
        }

        TrainingReportExample example = new TrainingReportExample();
        example.or().andUserIdIn(userIds)
                .andDeletedEqualTo(false);
        return trainingReportMapper.selectByExample(example);
    }

    public void deleteByUserIds(List<Long> userIds) {
        if (CollectionUtils.isEmpty(userIds)) {
            return;
        }

        TrainingReportExample example = new TrainingReportExample();
        example.or().andUserIdIn(userIds)
                .andDeletedEqualTo(false);

        TrainingReport trainingReport = TrainingReport.builder()
                .deleted(true)
                .build();
        trainingReportMapper.updateByExampleSelective(trainingReport, example);
    }
}
